package com.huyn.baseframework.net;

import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkInfo.State;

/**
 * Created by huyn on 2015/9/22.
 */
public class NetStateHelper {

    public static boolean isNetConnected(Context context) {
        ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
        State wifiState = cm.getNetworkInfo(ConnectivityManager.TYPE_WIFI).getState();
        State  mobileState = cm.getNetworkInfo(ConnectivityManager.TYPE_MOBILE).getState();
        if(wifiState == null || mobileState == null)
            return false;
        if (State.CONNECTED != wifiState && State.CONNECTED != mobileState)
            return false;
        return true;
    }

    public static boolean isWifiConnected(Context context) {
        ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
        State wifiState = cm.getNetworkInfo(ConnectivityManager.TYPE_WIFI).getState();
        if(wifiState != null || State.CONNECTED == wifiState)
            return true;
        return false;
    }

}
